﻿using System;
using System.Collections.Generic;
using System.Text;

namespace csharpcore7_ch3
{
    class GenericExample4
    {
        static void _Main()
        {
            var bears = new Stack<Bear>();
            bears.Push(new Bear());
            //bears 实现了IPopable<Bear>接口，我们可以将其转换到IPopable<Animal>。
            IPopable<Animal> animals = bears;       //Legal
            Animal a = animals.Pop();
            //bears.Push(new Camel());//  Illegal


            //逆变,声明一个可压入的Animal的Stack。
            IPushable<Animal> animials1 = new Stack<Animal>();
            IPushable<Bear> bears1 = animials1;
            bears1.Push(new Bear());


            var objectComparer = Comparer<object>.Default;
            IComparer<string> stringComparer = objectComparer;
            int result = stringComparer.Compare("Brett","Jemaine");
        }
    }
}
